<?php
namespace Agent\Controller;
use Think\Controller;
class DownloadController extends BaseController {
	public function import(){
		$id=I('id');
		$filename = "./data/".$id;
		if($id=='1.xls'){
			$filename = "./data/list_product.xls";
		}
		if($id=='2.xls'){
			$filename = "./data/product.xls";
		}
		$this->download_file($filename);
	}
	//下载文件
	function download_file($file){
		if(is_file($file)){
			$length = filesize($file);
			$type = filetype($file);
			$showname =  ltrim(strrchr($file,'/'),'/');
			header("Content-Description: File Transfer");
			header('Content-type: ' . $type);
			header('Content-Length:' . $length);
			 if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) { //for IE
				 header('Content-Disposition: attachment; filename="' . rawurlencode($showname) . '"');
			 } else {
				 header('Content-Disposition: attachment; filename="' . $showname . '"');
			 }
			 readfile($file);
			 exit;
		 } else {
			 exit('文件已被删除！');
		 }
	 }
}